<?php


namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Models\FleaBanner;
use App\Models\Mini\FleaGoodsModel;
use App\Services\FleaGoodsService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class FleaGoodsController extends Controller
{
    public $model;
    protected $service;

    public function __construct(FleaGoodsService $fleaGoodsService){
        $this->model = new FleaGoodsModel();
        $this->service = $fleaGoodsService;
    }

    /**
     *banner列表
     * @param Request $request
     * @return array
     */
    public function index(Request $request)
    {
        $user = Auth::user();
        $param = $request->query();
        //查询当前物业自己添加的数据
        $where['status'] = 1;
        if (isset($param['estate_id']) && !empty($param['estate_id'])) $where['estate_id'] = $param['estate_id'];
        if (isset($param['cate_id']) && !empty($param['cate_id'])) $where['cate_id'] = $param['cate_id'];
        if (isset($param['name']) && !empty($param['name'])) $where[] = ['name','like',"%{$param['name']}%"];
        return $this->success( $this->service->getList($where ,'id','desc'));
    }

    /**
     * 获取详情
     * @param $id
     * @return array
     */
    public function show($id)
    {
        $info = $this->service->detail($id,2);
        return $info['status'] ? $this->success($info['data']) : $this->error($info['msg']);
    }

    /**
     * 删除
     * @param Request $request
     * @return array
     */
    public function destroy($id)
    {
        $param = explode('&',$id);
        $id = $param[0];
        $note = $param[1];
        $info = $this->service->pcDelete($id,$note,4);
        return $info['status'] ? $this->success($info['data']) : $this->error($info['msg']);
    }
}
